<template>
  <!-- 动态组件：通过 key 变化强制重新挂载 -->
  <component :is="currentComponent" :key="refreshKey" />
</template>

<script lang="ts" setup>
import {shallowRef, nextTick, provide, ref, onMounted} from 'vue';
import Chat from '@/components/Chat.vue';
import type { Component } from 'vue';
import axios from "axios"; // 引入组件类型

// 使用 shallowRef 避免组件被转为响应式对象
const currentComponent = shallowRef<Component | null>(Chat);
const refreshKey = ref(0);

const refreshParent = () => {
  refreshKey.value += 1;
  currentComponent.value = null; // 销毁组件
  nextTick(() => {
    currentComponent.value = Chat; // 重建组件
  });
};
provide('refreshParent', refreshParent);
const clear=async () => {
  const response = await axios.post('http://localhost:8080/conversations/clearHistory')
  if (response.data.code === 200) {
    console.log("清除历史对话成功");
  }
}
onMounted(() => {
  clear()
});
</script>